<?php
require_once($server->my_site[0]->path.$server->my_site[0]->folder."distributor_manage.php");

$distributor->id or exit("Área reservada a distribuidores");

$orders_ids=array();
if (isset($_GET['order_id'])) array_push($orders_ids, $_GET['order_id']);
else $orders_ids=explode(",",$_COOKIE['selectedOrders']);
$orders=array();
foreach ($distributor->unprocessed_orders as $order) {
	foreach ($orders_ids as $order_id) {
		if ($order->id==$order_id) array_push($orders, $order);
	}
}
foreach ($distributor->processed_orders as $order) {
	foreach ($orders_ids as $order_id) {
		if ($order->id==$order_id) array_push($orders, $order);
	}
}
?>
<div style="width:210mm;padding:15mm 10mm;">
<?php
#Vamos con las etiquetas
$labels=0;
if (isset($_GET['labels']) && $_GET['labels']=='1') {
	$labels=1;
?>
<div class="labels">
<?php

 foreach ($orders as $order) {
?>
	<div style="margin:1em 0;">

	<div style="font-size:11pt"><?php echo $order->delivery->address->firstname . " " . $order->delivery->address->lastname.'. '.$order->delivery->address->city.'.'; ?>
	 TLFNO/S: <?php echo $order->delivery->phone; if ($order->delivery->sec_phone) echo " " . $order->delivery->sec_phone;?>
	</div>
	<div style="font-size:12pt;font-weight:bold"><?php echo $order->comments; ?></div>
	</div>
	<hr>
<?php
}
?>
</div>
<?php
}
#Vamos con los albaranes
foreach ($orders as $order) {
?>
<div id="order<?php echo $order->id; ?>" style="font-size:9pt" class="PrintArea">
	<table	style="width:100%">
		<tr>
			<td style="text-align:left;width:50%;">
				<table class="orderAddress">
					<tr>
						<td><p><?php print "Ref. Num. " . ' ' . $order->id; ?></p></td>
					</tr>
					<tr>
						<td><?php print  $order->delivery->address->firstname . " " . $order->delivery->address->lastname; ?></td>
					</tr>
					<tr>
						<td><?php print $order->delivery->address->street; ?></td>
					</tr>
					<tr>
						<td><?php print $order->delivery->address->postcode . ' ' . $order->delivery->address->city; ?></td>
					</tr>
				</table>
			</td>
			<td style="text-align:right;">
				<table class="cnAddress">
					<tr>
						<td style="width:50px;"></td>
						<td>
							<table>
								<tr></tr>
								<tr>
									<td>CosmeticaNatural.com</td>
								<tr>
								<tr>
									<td>c/ Cabeza de vaca, 21, Bajo</td>
								</tr>
								<tr>
									<td>CP.37004 Salamanca Spain</td>
								</tr>
								<tr>
									<td>(+34) 656 64 22 79</td>
								</tr>
								<tr>
									<td>envios@cosmeticanatural.com</td>
								</tr>
								<tr>
									<td>www.cosmeticanatural.com</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>

	<table style="width:100%;margin: 15pt 0 20pt 0;">
		<tr>
			<td>
				<table class="orderCart">
					<tr>
						  <th style="width:60px">Cantidad </th>
						  <th>Producto </th>
						  <th style="width:80px;text-align: right;">Precio </th>
						  <th style="width:80px;text-align: right;">Total </th>
					</tr>
<?php
	foreach($order->items as $item) {
?>
					<tr class="product">
						<td>
							<?php print $item->name; ?>
						</td>
						<td class="quantity" style="text-align:center">
							<?php echo $item->quantity; ?>
						</td>
						<td class="price" style="text-align:right"><?php echo number_format($item->price, 2, ',', ' '); ?> €</td>
						<td class="total" style="text-align:right"><?php echo number_format($item->price * $item->quantity, 2, ',', ' '); ?> €</td>
					</tr>
<?php
	}
?>
					<tr>
						<td colspan="4" class="hr"></td>
					</tr>
					<tr class="total">
						<td colspan="3">Subtotal:</td>
						<td style="text-align:right"><?php print number_format($order->subTotal, 2, ',', ' '); ?> €</td>
					<tr class="total">
						<td colspan="3">Gastos de cobro:</td>
						<td style="text-align:right"><?php print number_format($order->payment->method->price, 2, ',', ' '); ?> €</td>
					</tr>
					<tr class="total">
						<td colspan="3">Gastos de envio:</td>
						<td style="text-align:right"><?php print number_format($order->delivery->shipping_type->price, 2, ',', ' '); ?> €</td>
					</tr>
					<tr class="total">
						<td colspan="3">Total:</td>
						<td style="text-align:right"><?php print number_format($order->price, 2, ',', ' '); ?> €</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</div>
<?php
}
?>
<script language="javascript">
printOrders(<?php echo $labels; ?>);
</script>
